<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('项目管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>状态：</label>
                            <select name="status">
                                <option value="">全部</option>
                                <option value="报告待审核">报告待审核</option>
                                <option value="审核不通过">审核不通过</option>
                                <option value="审核通过">审核通过</option>
                                <option value="已上传">已上传</option>
                            </select>
                        </li>
                        <li>
                            <label>项目名称：</label>
                            <input name="projectName" type="text"/>
                        </li>
                        <li>
                            <label>项目编号：</label>
                            <input name="projectCode" type="text"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:management:add">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>

<!-- 模态框 -->
<div aria-hidden="true" aria-labelledby="generateReportModalLabel" class="modal fade" id="generateReportModal"
     role="dialog"
     tabindex="-1">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="generateReportModalLabel">报告审核</h5>
                <button aria-label="Close" class="close" data-dismiss="modal" type="button">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label class="control-label">审核意见：</label>
                    <textarea class="form-control" id="reportContent" name="reportContent" rows="3"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary" data-dismiss="modal" type="button">取消</button>
                <button class="btn btn-primary" onclick="generateReport()" type="button">确定</button>
            </div>
        </div>
    </div>
</div>

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:management:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:management:remove')}]];
    var prefix = ctx + "system/managementsh";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "项目管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'status',
                    title: '状态'
                },
                {
                    field: 'projectCode',
                    title: '项目编号'
                },
                {
                    field: 'expectedDuration',
                    title: '预期工期'
                },
                {
                    field: 'estimatedCost',
                    title: '评估金额'
                },
                {
                    field: 'createdTime',
                    title: '创建时间'
                },
                {
                    field: 'updatedTime',
                    title: '更新时间'
                },
                {
                    field: 'bat',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        //根据状态显示 已上传显示生成报告
                        if (row.status !== '已上传') {
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="viewReport(\'' + row.id + '\')"><i class="fa fa-file-text"></i>详情报告</a>');
                            //加点间距
                            actions.push('&nbsp;&nbsp;');
                        }
                        if (row.status === '报告待审核') {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="pass(\'' + row.id + '\')"><i class="fa fa-check"></i>通过</a>');
                            actions.push('&nbsp;&nbsp;');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="showGenerateReportModal(\'' + row.id + '\')"><i class="fa fa-remove"></i>不通过</a>');
                            actions.push('&nbsp;&nbsp;');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function showGenerateReportModal(id) {
        $('#generateReportModal').data('row-id', id).modal('show');
    }

    function generateReport() {
        //发送请求
        var rowId = $('#generateReportModal').data('row-id');
        var bat = $('#reportContent').val();
        // 发送请求，将数据发送到后端进行处理
        $.ajax({
            url: prefix + '/edit',
            type: 'POST',
            data: {
                id: rowId,
                status: '审核不通过',
                bat: bat
            },
            success: function (response) {
                //关闭弹窗
                $('#generateReportModal').modal('hide');
                $.modal.msgSuccess('操作成功');
                $.table.search()
            }
        })
    }

    function pass(rowId) {
        $.modal.confirm("确定审核通过吗？", function () {
            $.ajax({
                url: prefix + '/edit',
                type: 'POST',
                data: {
                    id: rowId,
                    status: '审核通过'
                },
                success: function (response) {
                    //关闭弹窗
                    $.table.search()
                }
            })
        })
    }


    function viewReport(id) {
        //下载本地的word
        var fileId = id % 3;
        window.location.href = ctx + 'doc/示例项目' + (fileId === 0 ? 3 : fileId) + '.docx';
    }
</script>
</body>
</html>
